package com.ruoyi.web.controller.base;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.base.BaseStationMaterial;
import com.ruoyi.system.domain.base.BaseStationMaterialDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IBaseStationMaterialService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工位物料Controller
 *
 * @author ruoyi
 * @date 2023-12-07
 */
@Api(tags = "工位-物料API")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/base/stationMaterial" )
public class BaseStationMaterialController extends BaseController {

    private final IBaseStationMaterialService iBaseStationMaterialService;

    /**
     * 查询工位物料列表
     */
    @ApiOperation(value = "查询工位物料列表",response = BaseStationMaterialDTO.class)
//    @PreAuthorize("@ss.hasPermi('system:material:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseStationMaterial baseStationMaterial)
    {
        startPage();
        List<BaseStationMaterialDTO> list = iBaseStationMaterialService.pageList(baseStationMaterial);
        return getDataTable(list);
    }

    /**
     * 导出工位物料列表
     */
    @PreAuthorize("@ss.hasPermi('system:material:export')" )
    @Log(title = "工位物料" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(BaseStationMaterial baseStationMaterial) {
        LambdaQueryWrapper<BaseStationMaterial> lqw = new LambdaQueryWrapper<BaseStationMaterial>(baseStationMaterial);
        List<BaseStationMaterial> list = iBaseStationMaterialService.list(lqw);
        ExcelUtil<BaseStationMaterial> util = new ExcelUtil<BaseStationMaterial>(BaseStationMaterial. class);
        return util.exportExcel(list, "material" );
    }

    /**
     * 获取工位物料详细信息
     */
    @ApiOperation(value = "获取工位物料详细信息")
    @PreAuthorize("@ss.hasPermi('system:material:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iBaseStationMaterialService.getById(id));
    }

    /**
     * 新增工位物料
     */
    @ApiOperation(value = "新增工位物料")
//    @PreAuthorize("@ss.hasPermi('system:material:add')" )
    @Log(title = "工位物料" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseStationMaterial baseStationMaterial) {
        return toAjax(iBaseStationMaterialService.save(baseStationMaterial) ? 1 : 0);
    }

    /**
     * 修改工位物料
     */
    @ApiOperation(value = "修改工位物料")
    @PreAuthorize("@ss.hasPermi('system:material:edit')" )
    @Log(title = "工位物料" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseStationMaterial baseStationMaterial) {
        return toAjax(iBaseStationMaterialService.updateById(baseStationMaterial) ? 1 : 0);
    }

    /**
     * 删除工位物料
     */
    @ApiOperation(value = "删除工位物料")
    @PreAuthorize("@ss.hasPermi('system:material:remove')" )
    @Log(title = "工位物料" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iBaseStationMaterialService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
